<html>
<head>
    <meta charset="utf-8" />
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="description" content="Alger的博客,这里有好多新奇的知识,以及一个小开发者的闲话">
<meta name="keywords" content="Alger,Alger的博客,alger,alger的博客,html,css,vue,刘俊杰的博客,刘俊杰,liujunjie,Alger开发,Android,刘先生">

<title> ASP.NET用PlaceHolder动态添加组件实现单选题目 | Alger&#39;s blog</title>

<link rel="shortcut icon" href="http://www.myalger.ml/favicon.ico?v=1598690869337">

<link href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" href="http://www.myalger.ml/styles/main.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css">

<script src="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets/highlight.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.15.10/languages/dockerfile.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.15.10/languages/dart.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/moment@2.27.0/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js"></script>
<!-- DEMO JS -->
<!--<script src="media/scripts/index.js"></script>-->


    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.css">
</head>
<body>
<div class="main gt-bg-theme-color-first">
    <nav class="navbar navbar-expand-lg">
    <div class="navbar-brand">
        <img class="user-avatar" src="/images/avatar.png" alt="头像">
        <div class="site-name gt-c-content-color-first">
            Alger&#39;s blog
        </div>
    </div>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <i class="fas fa-bars gt-c-content-color-first" style="font-size: 18px"></i>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <div class="navbar-nav mr-auto" style="text-align: center">
            
                <div class="nav-item">
                    
                        <a href="/" class="menu gt-a-link">
                            首页
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="/archives" class="menu gt-a-link">
                            归档
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="/tags" class="menu gt-a-link">
                            标签
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="http://www.myalger.ml/about" class="menu gt-a-link">
                            关于
                        </a>
                    
                </div>
            
        </div>
        <div style="text-align: center">
            <form id="gridea-search-form" style="position: relative" data-update="1598690869337" action="/search/index.html">
                <input class="search-input" autocomplete="off" spellcheck="false" name="q" placeholder="搜索文章" />
                <i class="fas fa-search gt-c-content-color-first" style="position: absolute; top: 9px; left: 10px;"></i>
            </form>
        </div>
    </div>
</nav>

    <div class="post-container">
        <div class="post-detail gt-bg-theme-color-second">
            <article class="gt-post-content">
                <h2 class="post-title">
                     ASP.NET用PlaceHolder动态添加组件实现单选题目
                </h2>
                <div class="post-info">
                    <time class="post-time gt-c-content-color-first">
                        · 2020-03-13 ·
                    </time>
                    
                        <a href="http://www.myalger.ml/NQvaoSPkJ/" class="post-tags">
                            # ASP.NET
                        </a>
                    
                </div>
                <div class="post-content">
                    <p>利用<code>PlaceHolder</code>控件实现一个包含单项选择题的测试页面，其中题目信息包含于数组中。</p>
<!-- more -->
<p>ASP页面🎈</p>
<pre><code class="language-asp"> &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
     &lt;div&gt;
         &lt;asp:PlaceHolder ID=&quot;PlaceHolder1&quot; runat=&quot;server&quot;&gt;&lt;/asp:PlaceHolder&gt;
         &lt;br /&gt;
         &lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; Text=&quot;Button&quot; OnClick=&quot;Button1_Click&quot; /&gt;
     &lt;/div&gt;
&lt;/form&gt;
</code></pre>
<p>类文件🎈（多选）</p>
<pre><code class="language-C#">protected void Page_Load(object sender, EventArgs e)
{
    //题目
    string[,] tit = new string[2, 4] 
    { 
        {   &quot;(1）数a分解质因数是a=2×2×3，数b分解质因数是b=2×2×5，数a和数b的最大公因数是（）&quot;,
         &quot;(2)已知3个数的和是470，第一个数比第二个数多160，第三个数比第一个数少180，这三个数的最大公因数是（)&quot;,
         &quot;（3）下列选项中的数是序数的是（)&quot;,
         &quot;（4）某地区的电话号码是一个八位数，已知其前四位数是一个固定数6869，那么该地区最多可安装（）部电话。&quot;
        },
        //答案
        {&quot;B&quot;,&quot;C&quot;,&quot;D&quot;,&quot;C&quot;}
    };
    //选项
    string[,] answer = new string[4, 4]
    { 
        { &quot;A 2&quot;, &quot;B 4&quot;, &quot;C 6 &quot;, &quot;D 60&quot; }, 
        { &quot;A 20&quot;, &quot;B 12&quot;, &quot;C 10&quot;, &quot;D 2&quot; }, 
        { &quot;A 6只鸡&quot;, &quot;B 5支铅笔&quot;, &quot;C 2栋楼房&quot;, &quot;D 第2节课&quot; }, 
        { &quot;A 6869 &quot;, &quot;B 9999 &quot;, &quot;C 10000&quot;, &quot;D 10001&quot; }
    };

    for(int j = 0; j&lt;4; j++)
    {
        Label title = new Label();     //动态添加题目
        title.ID = &quot;title&quot;+j.ToString();
        title.Text = tit[0,j];
        PlaceHolder1.Controls.Add(title);

        CheckBoxList check = new CheckBoxList();//题目添加选项
        check.ID = &quot;check&quot; + j.ToString();
        for (int i = 0; i &lt; 4; i++)
        {
            check.Items.Add(answer[j, i]);
        }
        PlaceHolder1.Controls.Add(check);
    }
}
</code></pre>
<p>这个是多选的代码，单选页面美化麻烦一点</p>
<p>类文件🎈（单选）</p>
<pre><code class="language-C#">protected void Page_Load(object sender, EventArgs e)
{
    //题目
    string[,] tit = new string[2, 4] 
    { 
        {   &quot;(1）数a分解质因数是a=2×2×3，数b分解质因数是b=2×2×5，数a和数b的最大公因数是（）&quot;,
         &quot;(2)已知3个数的和是470，第一个数比第二个数多160，第三个数比第一个数少180，这三个数的最大公因数是（)&quot;,
         &quot;（3）下列选项中的数是序数的是（)&quot;,
         &quot;（4）某地区的电话号码是一个八位数，已知其前四位数是一个固定数6869，那么该地区最多可安装（）部电话。&quot;
        },
        {&quot;B&quot;,&quot;C&quot;,&quot;D&quot;,&quot;C&quot;}//答案
    };
    //选项
    string[,] answer = new string[4, 4]
    { 
        { &quot;A 2&quot;, &quot;B 4&quot;, &quot;C 6 &quot;, &quot;D 60&quot; }, 
        { &quot;A 20&quot;, &quot;B 12&quot;, &quot;C 10&quot;, &quot;D 2&quot; }, 
        { &quot;A 6只鸡&quot;, &quot;B 5支铅笔&quot;, &quot;C 2栋楼房&quot;, &quot;D 第2节课&quot; }, 
        { &quot;A 6869 &quot;, &quot;B 9999 &quot;, &quot;C 10000&quot;, &quot;D 10001&quot; }
    };

    for(int j = 0; j&lt;4; j++)
    {
        Label title = new Label();     //动态添加题目
        title.ID = &quot;title&quot;+j.ToString();
        title.Text = tit[0,j];
        PlaceHolder1.Controls.Add(title);

        RadioButton[] radio = new RadioButton[4];
        for (int k = 0; k &lt; 4; k++)
        {
            radio[k] = new RadioButton();
            radio[k].ID = &quot;radio&quot; + j.ToString() + &quot;_&quot; + k.ToString();
            radio[k].GroupName = &quot;radio&quot; + j.ToString();
            radio[k].Text = answer[j, k];
            PlaceHolder1.Controls.Add(radio[k]);
        }
    }
}
</code></pre>

                </div>
            </article>
        </div>

        
            <div class="next-post">
                <div class="next gt-c-content-color-first">下一篇</div>
                <a href="http://www.myalger.ml/javascript-ji-chu-shu-ju-lei-xing/" class="post-title gt-a-link">
                    JavaScript基础- 数据类型🔨
                </a>
            </div>
        

        
            <span id="/aspnet-yong-placeholder-dong-tai-tian-jia-zu-jian-shi-xian-dan-xuan-ti-mu/" class="leancloud_visitors" data-flag-title=" ASP.NET用PlaceHolder动态添加组件实现单选题目">
                <em class="post-meta-item-text">阅读量 </em>
                <i class="leancloud-visitors-count">0</i>
            </span>
        

        

        
            <script src='https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js'></script>

<style>
	div#vcomments{
		width:100%;
		max-width: 1000px;
		padding: 2.5%
	}
</style>


	<div id="vcomments"></div>

<script>
	new Valine({
		el: '#vcomments',
		appId: 'zSod8O6f9ppLFYxB5PgGNotJ-gzGzoHsz',
		appKey: 'zPFYmL2RAeARE6sTWFnHfJg7',
		avatar: 'retro',
		pageSize: 10,
		recordIp: true,
		placeholder: 'Just Go Go',
		visitor: true,
	});
</script>

        

        <div class="site-footer gt-c-content-color-first">
    <div class="slogan gt-c-content-color-first">春风得意马蹄疾,一日看尽长安花.
</div>
    <div class="social-container">
        
            
        
            
        
            
        
            
        
            
        
            
        
    </div>
    <div class="footer-info">
        Powered by <a href="https://github.com/getgridea/gridea" target="_blank">Gridea</a>
    </div>
    <div>
        Theme by <a href="https://imhanjie.com/" target="_blank">imhanjie</a>, Powered by <a
                href="https://github.com/getgridea/gridea" target="_blank">Gridea | <a href="http://www.myalger.ml/atom.xml" target="_blank">RSS</a></a>
    </div>
</div>

<script>
  hljs.initHighlightingOnLoad()
</script>

    </div>
</div>
</body>
</html>
